var express=require("express");
var fs=require("fs")
var app=express();
app.listen(3000,function () {
    console.log(3000)
})

var msgArr = [];
app.post("/receiveMsg",function(req,res){
    // res.header("Access-Control-Allow-Origin","*");
    var param="";
    req.on("data",function(data){
        param+=data;
    });
    req.on("end",function(){
        msgArr.unshift(JSON.parse(param));
        fs.writeFile("msg.json",JSON.stringify(msgArr),"utf-8",function(err){
            if(err){
                console.log(err)
            }else(
                console.log("写入成功")

            )
        })
    });
    res.send("成功")
});

app.get("/dianpu",function (req,res) {
    res.header("Access-Control-Allow-Origin","*");
    res.sendFile(__dirname+"/data/shop"+req.query.pageNum+".json")
});

app.all("*",function (req,res) {
    res.header("Access-Control-Allow-Origin","*");
    res.sendFile(__dirname+req.url);
});